<template>
	<view class="requestlist">
		<u-navbar left-icon-color="#fff" :placeholder="true" :bgColor="bgColor" :autoBack="true">
			<view class="navtitle" slot="center">
				新的朋友
			</view>
		</u-navbar>
		<view class="chat-list" v-for="(item,index) in list" :key="index">
			<view class="chat-left">
				<u--image :showLoading="true" radius="10" :src="item.u_img"
					loadingIcon="/static/chat/logo.png" errorIcon="/static/chat/logo.png" width="55px"
					height="55px"></u--image>
			</view>
			<view class="chat-right">
				<view class="right-box">
					<view class="title">{{item.user}}</view>
					<view class="cont">{{item.message}}</view>
				</view>
				<view class="right-btn" v-if="item.status == 0">
					<u-button type="primary" color="#5FBC94" class="btn" text="同意" @click="goagree(item)"></u-button>
					<u-button type="primary" style="margin-left: 20rpx;" color="#FA5B5B" class="btn" text="拒绝" @click="refuse(item)"></u-button>
				</view>
				<view style="color: #5FBC94;font-size: 26rpx;" v-if="item.status == 1">
					已通过
				</view>
				<view style="color: #FA5B5B; font-size: 26rpx;" v-if="item.status == 2">
					已拒绝
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgColor: 'rgba(0,0,0,0.0)',
				userinfo: {},
				list:[]
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('info')
			this.postlist()
		},
		methods: {
			goagree(item){
				let params = {
					use_id: this.userinfo.member_id,
					id: item.id,
					status: 1
				}
				this.$Request({
					method: 'POST',
					url: '/api/rong/getBeVerifiedOperate',
					data: params
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title:"操作成功",
							icon:'none'
						})
						this.postlist()
					}
				})
			},
			refuse(item){
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否拒绝此好友请求！',
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							let params = {
								use_id: app.userinfo.member_id,
								id: item.id,
								status: 2
							}
							app.$Request({
								method: 'POST',
								url: '/api/rong/getBeVerifiedOperate',
								data: params
							}).then(res => {
								if (res.code == 1) {
									uni.showToast({
										title:"操作成功",
										icon:'none'
									})
									app.postlist()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			postlist() {
				let params = {
					use_id: this.userinfo.member_id
				}
				this.$Request({
					method: 'POST',
					url: '/api/rong/getBeVerified',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #17191A;
	}
</style>
<style scoped lang="scss">
	.requestlist {
		.navtitle {
			color: #fff;
		}

		.chat-list {
			display: flex;
			align-items: center;
			padding: 30rpx;

			.chat-left {
				width: 20%;
			}

			.chat-right {
				width: 80%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.right-box {

					.title {
						font-size: 28rpx;
						color: #fff;
					}

					.cont {
						font-size: 24rpx;
						color: #d6d6d6;
						margin-top: 20rpx;
					}
				}
				.right-btn{
					display: flex;
					align-items: center;
					.btn {
						width: 60px;
						height: 30px;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>